#include "gui_config.h"
#include <stdlib.h>
#include <string.h>

/*Screen 01: start_screen
    DEMO
  click ENTER
*/
static gui_ctrl gui_start_screen[] = 
{
  {LABEL_ID,"DEMO,1,5"},
  {BUTTON_START_CLICK,"click ENTER,2,2"},
};

/*Screen 02: list
    1.Temp
    2.Air
    3.Exit
*/
static gui_ctrl gui_list_screen[] = 
{
  {LIST_TEMP,"1.Temp,0,1"},
  {LIST_AIR ,"2.Air ,1,1"},
  {LIST_EXIT,"3.Exit,2,1"},
};

/*Screen 03:Temp
  Temp:39.1_
  Adj: _
  Back   Next
*/
static gui_ctrl gui_temp_screen[] = 
{
  {LABEL_ID         ,"Temp:,1,1"},
  {LABEL_ID         ,"Adj: ,2,2"},
  {BUTTON_TEMP_BACK ,"BACK ,3,3"},
  {BUTTON_TEMP_NEXT ,"NEXT ,3,9"},
  {TEXT_TEMP_VALUE  ,"text,39.1,1,10"}, //....
  {TEXT_TEMP_ADJ    ,"text,2c,2,10"}, //.... 
};

/*Screen 04:Air
  Air:   7 level
  Open Close
  Back   Next
*/
static gui_ctrl gui_air_screen[] = 
{
  {LABEL_ID        ,"Air: ,1,2"},
  {BUTTON_AIR_OPEN ,"OPEN ,2,3"},
  {BUTTON_AIR_CLOSE,"CLOSE,2,9"},
  {BUTTON_AIR_BACK ,"BACK ,3,3"},
  {BUTTON_AIR_NEXT ,"NEXT ,3,9"},
};

/*Screen 05:Password
  Password:
  ______
*/
static gui_ctrl gui_password_screen[] = 
{
  {LABEL_ID        ,"Password: ,1,2"},
  {TEXT_PASSWORD   ,"text,length:6,2,2"}, 
};

/*Screen 06:PSWRONG
  Password WRONG
    BACK
*/
static gui_ctrl gui_pswrong_screen[] = 
{
  {LABEL_ID        ,"Password Wrong!,1,2"},
  {BUTTON_PASWRONG ,"BACK,2,5"}, 
};


gui_screen gui_list[] = 
{
  {SCREEN_START  ,gui_start_screen,2},
  {SCREEN_LIST   ,gui_list_screen ,3},
  {SCREEN_TEMP   ,gui_temp_screen ,6},
  {SCREEN_AIR    ,gui_air_screen  ,5},
  {SCREEN_PSW    ,gui_password_screen,2},
  {SCREEN_PSWRONG,gui_pswrong_screen ,2},
};

int get_gui_screen(U16 screen_id,gui_screen *screen)
{
    int i;
    gui_screen *plist = NULL;
    
    for(i = 0;i < sizeof(gui_list) / sizeof(gui_screen);i++)
    {
        if(gui_list[i].screen_id == screen_id)
            plist = &(gui_list[i]);
    }
    
    if(plist == NULL)
       return 0;
    
    *screen = *plist;
    for(i = 0;i < screen->count;i++)
        screen->ctrls[i] = plist->ctrls[i];

    return 1;
}

void get_gui_info(char *descript,gui_info *info)
{
    char *p,*q;
    char s[40];	
    int order = 0;
       
    if(descript == NULL)
        return;
    
    q = descript;  
    do
    {
        p = strchr(q,',');
       
        if(p != NULL)
        {
            strncpy(s,q,p - q);
            s[p - q] = 0;
            q = p + 1;
        }
        else
            strcpy(s,q);
        
        if(strcmp(s,"text") == 0)
        {
            p = strchr(q,',');
            if(p != NULL)
            {
                strncpy(s,q,p - q);
                s[p - q] = 0;
                q = p + 1;
            } 
        }

        switch(order)
        {
            case 0:
              strcpy(info->string,s);
              break;
            
            case 1:
              info->row = atoi(s);
              break;
              
            case 2:
              info->column = atoi(s);
              break;
              
            default:
              break;
        }
        order++;
            
    }while(p != NULL);	 
}


// end of file -------------------

